var websocket = null;
function openConsult() {
    if ('WebSocket' in window) {
        websocket = new WebSocket("ws://localhost:8080/websocket/consult");
    }
    else if ('MozWebSocket' in window) {
        websocket = new MozWebSocket("ws://localhost:8080/websocket/consult");
    }
    else {
        websocket = new SockJS("http://localhost:8080/sockjs/consult");
    }
    websocket.onopen = onOpen;
    websocket.onmessage = onMessage;
    websocket.onerror = onError;
    websocket.onclose = onClose;
}

function onOpen(openEvt) {
    // alert(openEvt.data);

}

function onMessage(evt) {
    setMessageInnerHTML(evt.data)
    // alert(evt.data);
}
function onError() {}
function onClose() {}
function setMessageInnerHTML(innerHTML) {
    document.getElementById('message').innerHTML+=innerHTML+'<br/>'
}

function doSend(msg) {
    if (websocket.readyState === websocket.OPEN) {
        d = new Date();
        // var msg = document.getElementById("inputMsg").value;
        msg='From:'+userInfo.username+' '+d.getFullYear()
            +'年'+(d.getMonth()+1)+'月'+d.getDate()
            +'日'+d.getHours()+':'+d.getMinutes()
            +':'+d.getSeconds()+":\n"+msg;
        websocket.send(msg);//调用后台handleTextMessage方法
        alert("发送成功!");
    } else {
        alert("连接失败!");
    }
}
window.close=function()
{
    websocket.onclose();
};